home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / examples / cex2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-07  |  2.2 KB  |  142 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #define    PI    3.14159265358979
  5. #define    N    300
  6.  
  7.  
  8. #ifdef SGI_GL
  9. #include "gl.h"
  10. #include "device.h"
  11. #else
  12. #include "vogl.h"
  13. #include "vodevice.h"
  14. #endif
  15.  
  16.  
  17. float    x[N], y[N];
  18.  
  19. /*
  20.  *    Another very simple test program for vopl.
  21.  *
  22.  *     This one also draws a graph of y = sin(x) 0 <= x <= 2 * PI
  23.  *    but shows some of the axis and range setting stuff
  24.  */
  25. main()
  26. {
  27.     int    i;
  28.     float    t, dt;
  29.     short    val;
  30.     Screencoord     left, right, bottom, top;
  31.  
  32. /*
  33.  *    Generate the points
  34.  */
  35.     t = 0.0;
  36.     dt = 2 * PI / N;
  37.  
  38.     for (i = 0; i != N; i++) {
  39.         x[i] = t;
  40.         y[i] = sin(t);
  41.         t = t + dt;
  42.     }
  43.  
  44. /*
  45.  *    Set the X-scaling to be absolute 0 - 10 (ie no auto-scaling)
  46.  */
  47.     range(0.0, 10.0, 'x');
  48. /*
  49.  *    Autoscale the Y-axis
  50.  */
  51.     adjustscale(y, N, 'y');
  52. /*
  53.  *    Anyone for some axis titles?
  54.  */
  55.     axistitle("This one's for you", 'x');
  56.     axistitle("This one's for me", 'y');
  57. /*
  58.  *    As we are now about to do some graphics we initialise VOGLE
  59.  *    and clear to BLACK
  60.  */
  61.     hfont("futura.l");
  62.     winopen("VOPL");
  63.     qdevice(KEYBD);
  64.     color(0);
  65.     clear();
  66. /*
  67.  *    Now set the color to GREEN
  68.  */
  69.     color(2);
  70.  
  71. /*
  72.  *    Draw the default set of axes (in GREEN)
  73.  */
  74.     drawaxes2();
  75. /*
  76.  *    Set color to RED
  77.  */
  78.     color(1);
  79. /*
  80.  *    Draw the Graph
  81.  */
  82.     plot2(x, y, N);
  83. /*
  84.  *    Wait around a bit
  85.  */
  86.     qread(&val);
  87. /*
  88.  *    Now draw a little one in the top right hand corner
  89.  *    by reseting the VOGLE viewport.
  90.  */
  91.     getviewport(&left, &right, &bottom, &top);
  92.     viewport((left + right) / 2, right, (top + bottom) / 2, top);
  93. /*
  94.  *    Draw it again, but do the plot first (in BLUE) then the axes
  95.  *    (in YELLOW)
  96.  */
  97.     color(4);
  98.     plot2(x, y, N);
  99.     color(3);
  100.     drawaxes2();
  101. /*
  102.  *    Hang around again
  103.  */
  104.     qread(&val);
  105. /*
  106.  *    Clear it all away
  107.  */
  108.     viewport(left, right, bottom, top);
  109.     color(0);
  110.     clear();
  111. /*
  112.  *    Reset the viewport to be a "long skinny one"
  113.  */
  114.     viewport(left, right, bottom + (top + bottom) / 3, top - (top + bottom)/3);
  115. /*
  116.  *    Autoscale the X-axis again by first setting a ridicuous scale with
  117.  *    range that adjustscale will change.
  118.  */
  119.     range(1000.0, -1000.0, 'x');
  120.     adjustscale(x, N, 'x');
  121. /*
  122.  *    Change the X-axis title
  123.  */
  124.     axistitle("Blark Bonk Bloot", 'x');
  125. /*
  126.  *    And draw it all again...
  127.  */
  128.     color(5);
  129.     drawaxes2();
  130.     color(6);
  131.     plot2(x, y, N);
  132. /*
  133.  *    Hang around again
  134.  */
  135.     qread(&val);
  136. /*
  137.  *    Bugger off...
  138.  */
  139.  
  140.     gexit();
  141. }
  142.